# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models


# Create your models here.
class Author(models.Model):
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)
    email = models.EmailField()

    def __unicode__(self):
        return "<%s--%s>" % (self.first_name, self.last_name, )


class Publisher(models.Model):
    name = models.CharField(max_length=64, unique=True)
    address = models.CharField(max_length=128)
    city = models.CharField(max_length=64)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

    def __unicode__(self):
        return "<%s>" % (self.name,)


STATUS_CHOICES = (
    ('checkout', u'已出版'),
    ('wait', u'待出版'),
    ('checking', u'审核中'),
    ('Unknown', u'未知状态'),
)


class Book(models.Model):
    name = models.CharField(max_length=64)
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher)
    # publish_date = models.DateField(auto_now_add=True)
    publish_date = models.DateField()
    publish_status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='Unknown')

    def ALL_authors(self):
        return " , ".join((p.last_name + p.first_name) for p in self.authors.all())

    def __unicode__(self):
        return "<%s--%s>" % (self.name, self.publish_date, )
